package com.opencloud.iot.provider.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.opencloud.common.model.PageParams;
import com.opencloud.iot.client.model.entity.IotDayMoveResult;
import com.opencloud.iot.client.model.entity.IotDaySleepResult;
import com.opencloud.iot.provider.mapper.IotDayMoveResultMapper;
import com.opencloud.iot.provider.mapper.IotDaySleepResultMapper;
import com.opencloud.iot.provider.service.IotDayMoveResultService;
import com.opencloud.iot.provider.service.IotDaySleepResultService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 动量服务
 * @author yeyong
 */

@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class IotDayMoveResultServiceImpl implements IotDayMoveResultService {
    @Autowired
    private IotDayMoveResultMapper iotDayMoveResultMapper;

    /**
     * 获取每日运动统计
     * @param watchmac
     * @param thisdate
     * @return
     */
    @Override
    public List<IotDayMoveResult> findListPage(String watchmac,String thisdate) {
        QueryWrapper<IotDayMoveResult> queryWrapper = new QueryWrapper();
        queryWrapper.lambda().eq(ObjectUtils.isNotEmpty(thisdate),IotDayMoveResult::getThisdate,thisdate);
        queryWrapper.lambda().eq(ObjectUtils.isNotEmpty(watchmac),IotDayMoveResult::getWatchmac,watchmac);
        //queryWrapper.lambda().between(ObjectUtils.isNotEmpty(StartDate) && ObjectUtils.isNotEmpty(EndDate),IotDaySleepResult::getThisdate, StartDate, EndDate);
        queryWrapper.lambda().orderByDesc(IotDayMoveResult::getCreatetime);
        return iotDayMoveResultMapper.selectList(queryWrapper);
    }

    @Override
    public Integer addIotDayMoveResult(IotDayMoveResult entiy)
    {
        return iotDayMoveResultMapper.insert(entiy);
    }

    @Override
    public Integer updateIotDayMoveResult(IotDayMoveResult entiy)
    {
        return iotDayMoveResultMapper.updateById(entiy);
    }
}
